# 6a17c887d6054e798c9c88f4ca76f932
# 6a17c887d6054e798c9c88f4ca76f93220  缩略图  + t*10
# 6a17c887d6054e798c9c88f4ca76f93221  缩略图  + t*10 + 1
# 6a17c887d6054e798c9c88f4ca76f93229  高清图  + t*10 + 9

# d4f0a9ce880411ebb6edd017c2d2eca2
# d4f0a9ce880411ebb6edd017c2d2eca210  缩略图  + t*10
# d4f0a9ce880411ebb6edd017c2d2eca211  缩略图  + t*10 + 1
# d4f0a9ce880411ebb6edd017c2d2eca219  高清图  + t*10 + 9


import requests
import os
import time


root = "./images"
if not os.path.exists(root):
    os.mkdir(root)
thumb_root = os.path.join(root, "thumb_images")
if not os.path.exists(thumb_root):
    os.mkdir(thumb_root)
preview_root = os.path.join(root, "preview_images")
if not os.path.exists(preview_root):
    os.mkdir(preview_root)
big_root = os.path.join(root, "big_images")
if not os.path.exists(big_root):
    os.mkdir(big_root)


for page in range(1, 1734):
    print(f"正在爬取第{page}页")
    url = "https://api.zzzmh.cn/v2/bz/v3/getData"
    json_data = {
        "size": 24,
        "current": page,
        "sort": 0,
        "category": 0,
        "resolution": 0,
        "color": 0,
        "categoryId": 0,
        "ratio": 0
    }
    res = requests.post(url, json=json_data)
    if res.status_code == 200:
        for item in res.json()['data']['list']:
            i = item['i']
            t = item['t']
            print(f"正在爬取图片{i}")
            # 缩略图
            thumb_url = f'https://api.zzzmh.cn/v2/bz/v3/getUrl/{i}{t*10}'
            thumb_res = requests.get(thumb_url)
            with open(f"{thumb_root}/thumb_{i}.jpg", "wb") as f:
                f.write(thumb_res.content)

            # 预览图
            preview_url = f'https://api.zzzmh.cn/v2/bz/v3/getUrl/{i}{t*10+1}'
            preview_res = requests.get(preview_url)
            with open(f"{preview_root}/preview_{i}.jpg", "wb") as f:
                f.write(preview_res.content)
            # 高清图
            big_url = f'https://api.zzzmh.cn/v2/bz/v3/getUrl/{i}{t*10+9}'
            big_res = requests.get(big_url)
            with open(f"{big_root}/big_{i}.jpg", "wb") as f:
                f.write(big_res.content)

            time.sleep(1)
    else:
        print(f"获取页面数据异常")

    break
